package com.yq.design.factory;

import com.yq.design.factory.factory.AppleFactory;
import com.yq.design.factory.factory.XiaomiFactory;
import com.yq.design.factory.simple.Factory;

/**
 * @ClassName Client
 * @Description 工厂模式
 * @Author yaoqiang
 * @Date 2021/3/9 11:26
 * @Version 1.0
 * 简单工厂模式,匹配对应的具体产品，抽象Phone有make，xiaomi和apple分别实现make就行,工厂只需要根据传入的type，去new Xiaomi();
 * 工厂模式：1.抽象接口Phone有make,xiaomi类和apple类分别实现make就行,
 *          2.抽象工厂factory有makePhone,
 *          3.xiaomiFactory去实现make,返回Phone,AppleFactory去实现make,返回Phone,
 * 抽象工厂模式：1.抽象接口Phone有make,xiaomi类和apple类分别实现make就行,抽象接口Pc有make,xiaomiPc类和applePc类分别实现make就行,
 *              2.抽象工厂factory有makePhone,makePc
 *             3.xiaomiFactory去实现makePhone,makePc,返回Phone和pc,AppleFactory去实现makePhone,makePc,分别返回Phone和pc,
 */
public class FactoryClient {
    public static void main(String[] args) {
//        simple();
//        factory();
        abstractFactory();
    }

    public static void   simple(){
        Factory factory = new Factory();
        factory.makePhone("xiaomi").makePhone();
        factory.makePhone("apple").makePhone();
    }

    public static void   factory(){
        XiaomiFactory xiaomiFactory = new XiaomiFactory();
        AppleFactory appleFactory = new AppleFactory();
        xiaomiFactory.makePhone().makePhone();
        appleFactory.makePhone().makePhone();
    }

    public static void   abstractFactory(){
        com.yq.design.factory.abs.XiaomiFactory xiaomiFactory = new com.yq.design.factory.abs.XiaomiFactory();
        com.yq.design.factory.abs.AppleFactory appleFactory = new com.yq.design.factory.abs.AppleFactory();
        xiaomiFactory.makePc().make();
        xiaomiFactory.makePhone().makePhone();
        appleFactory.makePc().make();
        appleFactory.makePhone().makePhone();
    }
}
